package com.mzj.saas.mservice.house.service;

import com.mzj.saas.commons.DateUtils;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.commons.enums.*;
import com.mzj.saas.commons.vo.redis.TokenRedisVo;
import com.mzj.saas.mservice.announcement.entity.Announcement;
import com.mzj.saas.mservice.announcement.repository.AnnouncementRepository;
import com.mzj.saas.mservice.area.entity.Area;
import com.mzj.saas.mservice.area.repository.AreaRepository;
import com.mzj.saas.mservice.backlog.entity.BacklogItem;
import com.mzj.saas.mservice.backlog.entity.BacklogItemRent;
import com.mzj.saas.mservice.backlog.repository.BacklogItemRentRepository;
import com.mzj.saas.mservice.backlog.repository.BacklogItemRepository;
import com.mzj.saas.mservice.community.entity.Community;
import com.mzj.saas.mservice.community.entity.CommunityBuild;
import com.mzj.saas.mservice.community.entity.CommunityBuildUnit;
import com.mzj.saas.mservice.community.repository.CommunityBuildRepository;
import com.mzj.saas.mservice.community.repository.CommunityBuildUnitRepository;
import com.mzj.saas.mservice.community.repository.CommunityRepository;
import com.mzj.saas.mservice.eligible.entity.DepartmentHierarchy;
import com.mzj.saas.mservice.eligible.entity.Eligible;
import com.mzj.saas.mservice.eligible.entity.WaitingRentRecord;
import com.mzj.saas.mservice.eligible.repository.DepartmentHierarchyRepository;
import com.mzj.saas.mservice.eligible.repository.EligibleRepository;
import com.mzj.saas.mservice.eligible.repository.WaitingRentRecordRepository;
import com.mzj.saas.mservice.house.entity.House;
import com.mzj.saas.mservice.house.entity.HouseMatchUser;
import com.mzj.saas.mservice.house.entity.HousePublicity;
import com.mzj.saas.mservice.house.repository.HouseMatchUserRepository;
import com.mzj.saas.mservice.house.repository.HousePublicityRepository;
import com.mzj.saas.mservice.house.repository.HouseRepository;
import com.mzj.saas.mservice.house.vo.*;
import com.mzj.saas.mservice.sys.entity.AppUser;
import com.mzj.saas.mservice.sys.repository.AppUserRepository;
import com.mzj.saas.redis.RedisService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class RentService {
    private static final Logger log = LoggerFactory.getLogger(RentService.class);

    private static final String HOUSE_COUNT = "SELECT COUNT(1) ";
    private static final String HOUSE_COLUM = "SELECT h.id as houseId,h.residence_community_id as residenceCommunityId,h.building_num as buildingNum,h.unit,h.room_number as roomNumber, h.apply_code as applyCode ";
    private static final String HOUSE_FROM_MONITOR = " FROM saas_house h";
    private static final String ORDER_ORDER = " ORDER BY h.create_time DESC";
    private static final String SQL_PAGE = " LIMIT ? OFFSET ?";

    @Autowired
    private RedisService redisService;
    @Autowired
    private AppUserRepository appUserRepository;
    @Autowired
    private WaitingRentRecordRepository waitingRentRecordRepository;
    @Autowired
    private EligibleRepository eligibleRepository;
    @Autowired
    private AreaRepository areaRepository;
    @Autowired
    private HouseMatchUserRepository houseMatchUserRepository;
    @Autowired
    private HouseRepository houseRepository;
    @Autowired
    private CommunityRepository communityRepository;
    @Autowired
    private CommunityBuildRepository communityBuildRepository;
    @Autowired
    private CommunityBuildUnitRepository communityBuildUnitRepository;
    @Autowired
    private BacklogItemRepository backlogItemRepository;
    @Autowired
    private BacklogItemRentRepository backlogItemRentRepository;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HousePublicityRepository housePublicityRepository;
    @Autowired
    private AnnouncementRepository announcementRepository;
    @Autowired
    private DepartmentHierarchyRepository departmentHierarchyRepository;
    @Autowired
    private HouseService houseService;

    public ResultBean<List<WaitingRentRecordVO>> findWaitingUser(Long orgId, String residenceCommunityId, Long backlogItemId) {
        try {
            List<WaitingRentRecordVO> data;

            if (backlogItemId == null) {
                if (orgId == null) {
                    return ResultBean.failedResultOfParamWithMsg("产权人id为空");
                }
                if (StringUtils.isBlank(residenceCommunityId)) {
                    return ResultBean.failedResultOfParamWithMsg("小区id为空");
                }

                List<Object> args = new ArrayList<>();
                args.add(orgId);
                args.add(residenceCommunityId);
                //查未配租记录
                data = jdbcTemplate.query("SELECT r.id AS recordId,r.match_user_id,r.apply_id,a.city_id,a.district_id,a.street_id,a.community_id \n" +
                                "FROM saas_waiting_rent_record r \n" +
                                "LEFT JOIN `saas_house_eligible_apply` a ON r.apply_id = a.id  \n" +
                                "WHERE r.org_id = ? AND r.residence_community_id = ? AND r.status = 0",
                        new BeanPropertyRowMapper<>(WaitingRentRecordVO.class), args.toArray());
            } else {
                //待办事项
                BacklogItemRent backlogItemRent = backlogItemRentRepository.findByBacklogItemId(backlogItemId);
                if (backlogItemRent == null) {
                    return ResultBean.failedResultWithMsg("待办事项不存在");
                }
                Long applyId = backlogItemRent.getApplyId();

                data = jdbcTemplate.query("SELECT r.id AS recordId,r.match_user_id,r.apply_id,a.city_id,a.district_id,a.street_id,a.community_id \n" +
                                "FROM saas_waiting_rent_record r \n" +
                                "LEFT JOIN `saas_house_eligible_apply` a ON r.apply_id = a.id  \n" +
                                "WHERE r.apply_id = ?",
                        new BeanPropertyRowMapper<>(WaitingRentRecordVO.class), applyId);
            }

            // 查询申请人名称、手机号
            List<String> ids = data.stream().filter(vo -> vo.getMatchUserId() != null).map(WaitingRentRecordVO::getMatchUserId).distinct().collect(Collectors.toList());
            if (!ids.isEmpty()) {
                List<AppUser> users = appUserRepository.findByIdOrEnterpriseIn(ids, ids);
                for (WaitingRentRecordVO vo : data) {
                    for (AppUser user : users) {
                        if (vo.getMatchUserId().equals(user.getId()) || vo.getMatchUserId().equals(user.getEnterpriseUserId())) {
                            vo.setMatchUserName(user.getName());
                            vo.setPhone(user.getPhone());
                        }
                    }
                }
            }

            // 查询资格申请区域
            List<Long> areaIds = new ArrayList<>();
            List<Long> cityIds = data.stream().filter(vo -> vo.getCityId() != null).map(WaitingRentRecordVO::getCityId).distinct().collect(Collectors.toList());
            List<Long> districtIds = data.stream().filter(vo -> vo.getDistrictId() != null).map(WaitingRentRecordVO::getDistrictId).distinct().collect(Collectors.toList());
            List<Long> streetIds = data.stream().filter(vo -> vo.getStreetId() != null).map(WaitingRentRecordVO::getStreetId).distinct().collect(Collectors.toList());
            List<Long> communityIds = data.stream().filter(vo -> vo.getCommunityId() != null).map(WaitingRentRecordVO::getCommunityId).distinct().collect(Collectors.toList());
            areaIds.addAll(cityIds);
            areaIds.addAll(districtIds);
            areaIds.addAll(streetIds);
            areaIds.addAll(communityIds);
            if (!ids.isEmpty()) {
                Map<Long, String> map = areaRepository.findByIdIn(areaIds).stream().collect(Collectors.toMap(Area::getId, Area::getName));
                if (!map.isEmpty()) {
                    for (WaitingRentRecordVO vo : data) {
                        vo.setCity(map.get(vo.getCityId()));
                        vo.setDistrict(map.get(vo.getDistrictId()));
                        vo.setStreet(map.get(vo.getStreetId()));
                        vo.setCommunity(map.get(vo.getCommunityId()));
                    }
                }
            }

            return ResultBean.successfulResult(data);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultBean.failedResultOfException();
        }
    }

    public ResultBean<CanRentHouseDataVO<CanRentHouseVO>> canRentHouse(Integer pageNumber, Integer pageSize, String id, Long backlogItemId,
                                                                       Long buildingNum, Long unit, String roomNumber, String matchUserId) {
        log.info("RentService canRentHouse, id={}, backlogItemId={}, buildingNum={}, unit={}, roomNumber={}, matchUserId={}", id, backlogItemId,
                buildingNum, unit, roomNumber, matchUserId);
        ResultBean<CanRentHouseDataVO<CanRentHouseVO>> resultBean = new ResultBean<>();
        resultBean.setCode("10000");
        resultBean.setMsg("10000");
        CanRentHouseDataVO<CanRentHouseVO> apiData = new CanRentHouseDataVO<>();
        resultBean.setResultData(apiData);
        try {
            if (StringUtils.isBlank(id) && backlogItemId == null) {
                return ResultBean.failedResultOfParamWithMsg("待办事项id为空");
            }

            StringBuilder where = new StringBuilder();
            List<Object> args = new ArrayList<>();
            where.append(" where 1 = 1");

            if (!StringUtils.isBlank(id)) {
                where.append(" and h.id = ?");
                args.add(id);

                Optional<House> houseOpt = houseRepository.findById(id);
                if (!houseOpt.isPresent()) {
                    return ResultBean.failedResultWithMsg("公租房不存在");
                }
                apiData.setResidenceCommunityId(houseOpt.get().getResidenceCommunityId());
            } else {
                BacklogItemRent backlogItemRent = backlogItemRentRepository.findByBacklogItemId(backlogItemId);
                if (backlogItemRent == null) {
                    return ResultBean.failedResultWithMsg("待办事项配租参数数据不存在");
                }

                Long orgId = backlogItemRent.getOrgId();
                String residenceCommunityId = backlogItemRent.getResidenceCommunityId();

                where.append(" and h.audit_status = 1 and h.house_nature = 1");
                where.append(" and h.org_id = ?");
                args.add(orgId);

                where.append(" and h.residence_community_id = ?");
                args.add(residenceCommunityId);

                // 多承租人公租房，查询当前所选承租人配租批次号
                String applyCode = null;
                if (StringUtils.isNotEmpty(matchUserId)) {
                    List<Eligible> eligibleList = eligibleRepository.findByMatchUserIdAndMathStatus(matchUserId);
                    if (!eligibleList.isEmpty()) {
                        applyCode = eligibleList.get(0).getApplyCode();
                    }
                }

                // 多承租人公租房，已配租的房屋，相同批次号的承租人，可多次配租
                if (StringUtils.isNotEmpty(applyCode)) {
                    where.append(" and (h.match_status = ? or ((h.match_status = ? or h.match_status = ?) and h.apply_code = ?))");
                    args.add(HouseMatchStatusEnum.CAN_RENT.getValue());
                    args.add(HouseMatchStatusEnum.CAN_RENT.getValue());
                    args.add(HouseMatchStatusEnum.RENTED.getValue());
                    args.add(applyCode);
                } else {
                    where.append(" and h.match_status = ?");
                    args.add(HouseMatchStatusEnum.CAN_RENT.getValue());
                }

                if (buildingNum != null) {
                    where.append(" and h.building_num = ?");
                    args.add(buildingNum);
                }
                if (unit != null) {
                    where.append(" and h.unit = ?");
                    args.add(unit);
                }
                if (StringUtils.isNotBlank(roomNumber)) {
                    where.append(" and h.room_number = ?");
                    args.add(roomNumber);
                }

                apiData.setResidenceCommunityId(residenceCommunityId);
            }

            //总数
            Long total = jdbcTemplate.queryForObject(HOUSE_COUNT + HOUSE_FROM_MONITOR + where, args.toArray(), Long.class);
            if (total == 0) {
                return resultBean;
            }

            args.add(pageSize);
            args.add(pageNumber * pageSize);
            List<CanRentHouseVO> data = jdbcTemplate.query(HOUSE_COLUM + HOUSE_FROM_MONITOR + where + ORDER_ORDER + SQL_PAGE,
                    new BeanPropertyRowMapper<>(CanRentHouseVO.class), args.toArray());

            // 查询小区名称
            List<String> residenceCommunityIds = data.stream().filter(vo -> vo.getResidenceCommunityId() != null).map(CanRentHouseVO::getResidenceCommunityId).distinct().collect(Collectors.toList());
            if (!residenceCommunityIds.isEmpty()) {
                Map<String, String> map = communityRepository.findByIdIn(residenceCommunityIds).stream().collect(Collectors.toMap(Community::getId, Community::getName));
                if (!map.isEmpty()) {
                    data.forEach(vo -> vo.setResidenceCommunityName(map.get(vo.getResidenceCommunityId())));
                }
            }
            // 查询楼栋名称
            List<Long> buildingIds = data.stream().filter(vo -> vo.getBuildingNum() != null).map(CanRentHouseVO::getBuildingNum).distinct().collect(Collectors.toList());
            if (!buildingIds.isEmpty()) {
                Map<Long, String> map = communityBuildRepository.findByIdIn(buildingIds).stream().collect(Collectors.toMap(CommunityBuild::getId, CommunityBuild::getName));
                if (!map.isEmpty()) {
                    data.forEach(vo -> vo.setBuildingNumName(map.get(vo.getBuildingNum())));
                }
            }
            // 查询单元名称
            List<Long> unitIds = data.stream().filter(vo -> vo.getUnit() != null).map(CanRentHouseVO::getUnit).distinct().collect(Collectors.toList());
            if (!unitIds.isEmpty()) {
                Map<Long, String> map = communityBuildUnitRepository.findByIdIn(unitIds).stream().collect(Collectors.toMap(CommunityBuildUnit::getId, CommunityBuildUnit::getName));
                if (!map.isEmpty()) {
                    data.forEach(vo -> vo.setUnitName(map.get(vo.getUnit())));
                }
            }

            apiData.setData(data);
            apiData.setTotal(total);
            resultBean.setResultData(apiData);
        } catch (Exception e) {
            log.error("RentService canRentHouse Exception = {}" + e.getMessage(), e);
            resultBean.setCode("10001");
            resultBean.setMsg("10001");
        }
        resultBean.setResultData(apiData);
        return resultBean;
    }

    @Transactional
    public ResultBean<Object> rent(String accessToken, Long recordId, String houseId, Long applyId, String matchUserId, String applyCode) {
        try {
            log.info("RentService rent, recordId={}, houseId={}, applyId={}, matchUserId={}, applyCode={}", recordId, houseId, applyId, matchUserId, applyCode);
            if (recordId == null) {
                return ResultBean.failedResultOfParamWithMsg("轮候记录id为空");
            }
            if (StringUtils.isBlank(houseId)) {
                return ResultBean.failedResultOfParamWithMsg("公租房id为空");
            }
            if (applyId == null) {
                return ResultBean.failedResultOfParamWithMsg("申请id为空");
            }
            if (StringUtils.isBlank(matchUserId)) {
                return ResultBean.failedResultOfParamWithMsg("承租人id为空");
            }

            TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
            if (tokenRedisVo == null) {
                return ResultBean.failedResultOfToken();
            }
            String userId = tokenRedisVo.getId();
            Long enterpriseId = tokenRedisVo.getEnterpriseId();

            DepartmentHierarchy hierarchy = departmentHierarchyRepository.findByOrgIdAndStatus(enterpriseId, 1);
            if (hierarchy == null) {
                return ResultBean.failedResultWithMsg("用户所属机构未设置层级架构");
            }
            Integer publicityStatus = hierarchy.getPublicityStatus();//0关闭 1开启

            AppUser user = appUserRepository.findByIdOrEnterpriseUserId(matchUserId, matchUserId);
            if (user == null) {
                return ResultBean.failedResultWithMsg("承租人不存在");
            }

            // 验证当前承租人是否已存在状态正常的配租
            List<HouseMatchUser> mUsers = houseMatchUserRepository.findByMatchUserIdAndStatus(matchUserId, 1);
            if (!mUsers.isEmpty()) {
                return ResultBean.failedResultWithMsg("承租人已存在配租信息, 不可重复配租");
            }

            //新增配租成功记录
            List<HouseMatchUser> matchUserList = houseMatchUserRepository.findByApplyIdAndMatchUserId(applyId, matchUserId);
            if (!matchUserList.isEmpty()) {
                return ResultBean.failedResultWithMsg("承租人已存在配租信息, 不可重复配租");
            }
            Date date = new Date();
            HouseMatchUser matchUser = new HouseMatchUser();
            matchUser.setHouseId(houseId);
            matchUser.setApplyId(applyId);
            matchUser.setMatchUserId(matchUserId);
            matchUser.setStatus(MatchUserStatusEnum.NORMAL.getValue());
            matchUser.setOperatorTime(date);
            houseMatchUserRepository.save(matchUser);

            //公租房状态改成 已配租
            Optional<House> optional = houseRepository.findById(houseId);
            House house = optional.get();
            // 查询当前所选承租人配租批次号
            if (StringUtils.isEmpty(house.getApplyCode()) && StringUtils.isEmpty(applyCode)) {
                if (StringUtils.isNotEmpty(matchUserId)) {
                    List<Eligible> eligibleList = eligibleRepository.findByMatchUserIdAndMathStatus(matchUserId);
                    if (!eligibleList.isEmpty()) {
                        applyCode = eligibleList.get(0).getApplyCode();
                        house.setApplyCode(applyCode);
                        // 该公租房第一次配租时，类型默认为：单承租人类型
                        house.setMatchType(1);
                    }
                }
            } else if (StringUtils.isEmpty(house.getApplyCode()) && StringUtils.isNotEmpty(applyCode)) {
                house.setApplyCode(applyCode);
                // 该公租房第一次配租时，类型默认为：单承租人类型
                house.setMatchType(1);
            } else if (StringUtils.isNotEmpty(house.getApplyCode()) && StringUtils.isNotEmpty(applyCode)) {
                // 重复配租相同的公租房时，类型设置为：多承租人类型
                house.setMatchType(2);
            } else if (StringUtils.isNotEmpty(house.getApplyCode()) && StringUtils.isEmpty(applyCode)) {
                // 重复配租相同的公租房时，类型设置为：多承租人类型
                house.setMatchType(2);
            }
            house.setMatchStatus(HouseMatchStatusEnum.RENTED.getValue());
            houseRepository.save(house);

            //轮候记录状态改成已配租
            waitingRentRecordRepository.updateStatusById(recordId);

            //如果轮候表没有未配租记录，小区可配租房改成未配租
            Optional<WaitingRentRecord> recordOptional = waitingRentRecordRepository.findById(recordId);
            WaitingRentRecord record = recordOptional.get();
            Long orgId = record.getOrgId();
            String residenceCommunityId = record.getResidenceCommunityId();
            List<WaitingRentRecord> records = waitingRentRecordRepository.findByOrgIdAndResidenceCommunityIdAndStatus(orgId, residenceCommunityId, 0);
            if (records == null || records.size() == 0) {
                houseRepository.updateMatchStatus(residenceCommunityId, orgId, HouseMatchStatusEnum.CAN_RENT.getValue(), HouseMatchStatusEnum.NOT_RENT.getValue());
            }

            //资格申请状态改成已完成
            eligibleRepository.updateMatchStatus(applyId, EligibleMatchTypeEnum.DONE.getValue());

            if (publicityStatus == null || publicityStatus == 1) {
                //生成公示数据
                HousePublicity publicity = new HousePublicity();
                publicity.setAreaId(house.getCommunityId());
                publicity.setHouseId(houseId);
                publicity.setMatchUserId(matchUserId);
                publicity.setUserName(user.getName());
                publicity.setStartTime(date);
                publicity.setEndTime(DateUtils.getAddDaysTime(date, 10));
                housePublicityRepository.save(publicity);

                //新增或更新公告数据
                List<Announcement> announcements = announcementRepository.findByTypeAndAreaIdAndStatus(AnnouncementTypeEnum.PUBLICITY.getValue(), house.getCommunityId(), 1);
                if (!announcements.isEmpty()) {
                    Announcement announcement = announcements.get(0);
                    announcement.setOperationId(userId);
                    announcement.setReleaseTime(date);
                    announcementRepository.save(announcement);
                } else {
                    Announcement announcement = new Announcement();
                    announcement.setType(AnnouncementTypeEnum.PUBLICITY.getValue());
                    Area area = areaRepository.findByIdAndLevel(house.getCommunityId(), 5);
                    if (area == null) {
                        log.warn("轮候配租, 社区不存在, 无法生成公示, communityId={}", house.getCommunityId());
                    }else{
                    	announcement.setTitle(area.getName() + "公示");
                        announcement.setStatus(1);
                        announcement.setAreaId(house.getCommunityId());
                        announcement.setCommunityId(house.getResidenceCommunityId());
                        announcement.setOperationId(userId);
                        announcement.setReleaseTime(date);
                        announcementRepository.save(announcement);
                    }
                }
            }

            //修改待办事项状态
            BacklogItemRent backlogItemRent = backlogItemRentRepository.findByApplyId(applyId);
            if (backlogItemRent != null) {
                Optional<BacklogItem> backlogItemOpt = backlogItemRepository.findById(backlogItemRent.getBacklogItemId());
                if (!backlogItemOpt.isPresent()) {
                    log.warn("轮候配租，未找到对应待办事项");
                }else{
                	BacklogItem backlogItem = backlogItemOpt.get();

                    backlogItem.setBusinessStatus("已配租");
                    backlogItem.setHandleStatus(1);
                    backlogItem.setHandlerTime(date);
                    backlogItemRepository.save(backlogItem);
                }
            }

            //生成生成合同待办事项
            BacklogItem contractItem = new BacklogItem();
            contractItem.setHouseId(houseId);
            contractItem.setOrgId(orgId);
            contractItem.setType(BacklogItemTypeEnum.CONTRACT_CREATE.getValue());
            contractItem.setTitle(user.getName() + "申请的公租房合同待生成");
            contractItem.setContent("合同描述：配租已完成，请尽快生成合同");
            contractItem.setBusinessStatus("待生成");
            contractItem.setHandleStatus(0);
            contractItem.setOperatorId(userId);
            contractItem.setMatchUserId(matchUserId);
            contractItem.setPhone(user.getPhone());
            contractItem.setCreateTime(date);
            backlogItemRepository.save(contractItem);

            return ResultBean.successfulResult(null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
            return ResultBean.failedResultOfException();
        }
    }

    public ResultBean<BacklogRentInfoVO> backlogRentInfo(String accessToken, Long backlogItemId) {
        try {
            TokenRedisVo tokenRedisVo = redisService.findTokenVo(accessToken);
            if (tokenRedisVo == null) {
                return ResultBean.failedResultOfToken();
            }

            BacklogItemRent backlogItemRent = backlogItemRentRepository.findByBacklogItemId(backlogItemId);
            if (backlogItemRent == null) {
                return ResultBean.failedResultWithMsg("待办事项参数数据不存在");
            }
            Long applyId = backlogItemRent.getApplyId();

            String sql = "SELECT mu.match_user_id as matchUserId,mu.house_id AS houseId,a.apply_area as applyArea\n" +
                    "FROM saas_house_match_user mu\n" +
                    "LEFT JOIN `saas_house_eligible_apply` a ON mu.apply_id = a.id  \n" +
                    "WHERE mu.apply_id = ? AND mu.status = 1\n";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, applyId);

            BacklogRentInfoVO vo = new BacklogRentInfoVO();
            if (!list.isEmpty()) {
                Map<String, Object> map = list.get(0);

                //承租人信息
                String matchUserId = map.get("matchUserId").toString();
                vo.setMatchUserId(matchUserId);
                AppUser appUser = appUserRepository.findByIdOrEnterpriseUserId(matchUserId, matchUserId);
                if (appUser != null) {
                    vo.setMatchUserName(appUser.getName());
                    vo.setPhone(appUser.getPhone());
                }
                vo.setApplyArea(map.get("applyArea").toString());

                //房源信息
                String houseId = map.get("houseId").toString();
                ResultBean<HouseInfoVO> resultBean = houseService.findHouse(houseId);
                HouseInfoVO houseInfoVO = resultBean.getResultData();
                vo.setHouseId(houseId);
                vo.setResidenceCommunityName(houseInfoVO.getResidenceCommunityName());
                vo.setBuildingNumName(houseInfoVO.getBuildingNumName());
                vo.setUnitName(houseInfoVO.getUnitName());
                vo.setRoomNumber(houseInfoVO.getRoomNumber());
            }

            return ResultBean.successfulResult(vo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResultBean.failedResultOfException();
        }
    }


}
